package com.study.controller;


import com.study.model.entity.Student;
import com.study.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Admin
 * @since 2021-11-21
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @PostMapping("/add")
    public void add(@RequestBody Student student) {
        studentService.add(student);
    }

    @GetMapping("/delById/{id}")
    public void delById(@PathVariable("id") Long id) {
        studentService.delById(id);
    }

    @PostMapping("/update")
    public void update(@RequestBody Student student) {
        studentService.update(student);
    }

    /************重要*************/
    /*测试乐观锁*/
    @GetMapping("/testOptimisticLocker")
    public void testOptimisticLocker() {
        studentService.testOptimisticLocker();
    }

    /************重要*************/
    /*测试查询*/
    @GetMapping("/testQuery")
    public void testQuery() {
        studentService.testQuery();
    }

    /************重要*************/
    /*测试更新*/
    @GetMapping("/testUpdate")
    public void testUpdate() {
        studentService.testUpdate();
    }

    /*测试ActiveRecord模式*/
    @GetMapping("/testActiveRecord")
    public void testActiveRecord() {
        studentService.testActiveRecord();
    }

    @GetMapping("/testTypeHandler")
    public void test(){
        studentService.testTypeHandler();
    }

    /* 测试日期格式转换 */
    @PostMapping("/testDateConvert")
    public Date testDateConvert(@RequestParam("date") Date date) {
        return date;
    }

}

